<?php
require_once 'Artdepot/Controller/Action.php';

class NewsController extends Artdepot_Controller_Action
{

    public function init()
    {
		parent::init();
    }

    public function indexAction()
    {
    	//advertisements here
    	$adTable = new Model_DbTable_Advertisement(); 
	    $this->view->ads = $adTable->fetchAll("position = 2 and enabled = 1", "display_order ASC");
    	$perPage = 20;
    	$page = intval($this->_getParam('page', 1));
    	if ($page<1) {
    		$page = 1;
    	}
    	$newsTable = new Model_DbTable_News();
    	$totalItemsNum = $newsTable->getDefaultAdapter()->fetchOne("select count(*) from news");
    	$offset = ($page-1)*10;
		$totalPages = ceil($totalItemsNum/$perPage);
		$this->view->news = $news = $newsTable->fetchAll('id>30', array('display_order', 'id desc'), $perPage, $offset);
		$this->view->title = 'News - ';
		$this->view->pager = self::pager($page, $perPage, $totalItemsNum, '/news?page={page}');
    }
    
    public function showAction() {
    	$id = intval($this->_getParam('id', 0));
    	$newsTable = new Model_DbTable_News();
    	$this->view->news = $news = $newsTable->find($id)->current();
    	$this->view->title = htmlspecialchars($news->title) . ' - ';
    }


}

